/*
 *   Class Plotter
 *
 *   A free standing plotting application that takes data from
 *   an input file and plots a graph in a window
 *
 *   WRITTEN BY: Dr Michael Thomas Flanagan
 *
 *   DATE:    July 2002
 *   UPDATE:  22 June 2003, 14 August 2004, 7 July 2008
 *
 *   DOCUMENTATION:
 *   See Michael Thomas Flanagan's Java library on-line web page:
 *   Plotter.html
 *
 *   Copyright (c) 2002 - 2008
 *
 *   PERMISSION TO COPY:
 *   Permission to use, copy and modify this software and its documentation for
 *   NON-COMMERCIAL purposes is granted, without fee, provided that an acknowledgement
 *   to the author, Michael Thomas Flanagan at www.ee.ucl.ac.uk/~mflanaga, appears in all copies.
 *
 *   Dr Michael Thomas Flanagan makes no representations about the suitability
 *   or fitness of the software for any or for a particular purpose.
 *   Michael Thomas Flanagan shall not be liable for any damages suffered
 *   as a result of using, modifying or distributing this software or its derivatives.
 *
 ***************************************************************************************/

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;

import flanagan.io.*;
import flanagan.plot.*;


public class Plotter{
	
	private int nCurves = 0;        // number of curves
	private int[] nPoints = null;   // number of points per curve
	private int nMax = 0;           // maximum no of points on a curves
	private int ii = 0;             // counter

	private double[][] data = null;	// data points

	private String title =" ";      // plot title
	private String xLeg=" ";        // x axis legend
	private String xUnits=" ";      // x axis units
	private String yLeg=" ";        // y axis legend
	private String yUnits=" ";      // y axis units
	private String fileName=" "; 	// name of file containing input data
	private PlotGraph pg = null; 
	
	public Plotter(String fileName){
		this.fileName = fileName;
	}

	// main method
	public void Plot(){

		//int[] linesView = {1,1,0};
		
		FileInput fin = new FileInput(fileName);
		title = fin.readLine();
		xLeg = fin.readLine();
		xUnits = fin.readLine();
		yLeg = fin.readLine();
		yUnits = fin.readLine();

		nCurves = fin.readInt();
		nMax = fin.readInt();

		data = PlotGraph.data(nCurves,nMax);
		nPoints = new int[nCurves];
		ii=0;
		for(int i=0; i<nCurves; i++){
			nPoints[i]=fin.readInt();
			for(int j=0; j<nPoints[i]; j++){
				data[ii][j]=fin.readDouble();
				data[ii+1][j]=fin.readDouble();
			}
			ii+=2;
		}

		// Create a graph object
		pg = new PlotGraph(data);
		pg.setCloseChoice(2);
		//pg.setLine(linesView);
		pg.setPointSize(8);
		pg.setGraphTitle(title);
		pg.setXaxisLegend(xLeg);
		pg.setXaxisUnitsName(xUnits);
		pg.setYaxisLegend(yLeg);
		pg.setYaxisUnitsName(yUnits);
		
		// Call plotting method
		pg.plot();
	}
	
	
}

